﻿Axis = function() {
    Sim.Object.call(this);
};

Axis.prototype = new Sim.Object();
var xOpacity, yOpacity, zOpacity, scaleSize;
Axis.prototype.init = function (maxV, minV, step, effectController) {
    var group = new THREE.Object3D();
    this.setObject3D(group);
    xOpacity = effectController.X坐标透明度;
    yOpacity = effectController.Y坐标透明度;
    zOpacity = effectController.Z坐标透明度;
    scaleSize = effectController.坐标字体; 

    var maxX = (Math.floor(maxV.x / step) * step) + step, maxY = Math.floor(maxV.y / step) * step + step, maxZ = Math.floor(maxV.z / step) * step + step;
    var minX = Math.floor(minV.x / step) * step, minY = Math.floor(minV.y / step) * step, minZ = Math.floor(minV.z / step) * step;

    var xface = this.createXFace(maxX, maxZ, minX, minZ, step);
    xface.position.y += minY;
    var yface = this.createYFace(maxY, maxX, minY,minX, step);
    yface.position.z += minZ;
    var zface = this.createZFace(maxZ, maxY, minZ,minY, step);
    zface.position.x += minX;
    group.add(xface);
    group.add(yface);
    group.add(zface);
    this.group = group;
    this.yface = yface;
    this.zface = zface;
    
};



Axis.prototype.createXFace = function (maxa, maxb,mina,minb, step) {
    var face = new THREE.Object3D();

    var arrow = new THREE.ArrowHelper(new THREE.Vector3(1, 0, 0), new THREE.Vector3(mina, 0, minb), (maxa - mina) + 3 * step, 0xB22222, 10, 3);
    face.add(arrow);

//    var loader = new THREE.JSONLoader();
//    loader.load('js/dong.js', function (geometry, mat) {
//        var mesh = new THREE.Mesh(geometry, mat[0]);
//        mesh.scale.x = 5;
//        mesh.scale.y = 5;
//        mesh.scale.z = 5;
//        
//        mesh.position.set(maxa + 3 * step, -step, -step + minb);
//        face.add(mesh);
//    });

//    var loader = new THREE.JSONLoader();
//    loader.load('js/dong.js', function (geometry, mat) {
//        var mesh = new THREE.Mesh(geometry, mat[0]);
////        mesh.scale.x = 5;
////        mesh.scale.y = 5;
////        mesh.scale.z = 5;
//        
//        mesh.position.set(0,0,0);
//        face.add(mesh);
//    });
    
    if (xOpacity) {
        //添加x面
        var x1 = new THREE.RectangleHelper(maxa, maxb, mina, minb, step, xOpacity);

        face.add(x1);
    }
   

    //添加x文字。

    var xText = new THREE.THREEDTextHelper({ text: 'x' }, Tracking3DApp.Geometries);
    xText.position.set(maxa + 3 * step, -step, -step + minb);
    face.add(xText);

    for (var i = mina; i <= maxa; i += step ) {
//        var value = new THREE.TwoDTextHelper(i, 20, 10, 10);
        var value = new THREE.THREEDTextHelper({ text: i, size: scaleSize }, Tracking3DApp.Geometries);
        value.position.set(i, -step / 4, -step / 4 + minb);
        face.add(value);
    }

    return face;
};

Axis.prototype.createYFace = function (maxa, maxb, mina, minb, step) {
    var face = new THREE.Object3D();

    var arrow = new THREE.ArrowHelper(new THREE.Vector3(0, 1, 0), new THREE.Vector3(minb, mina, 0), (maxa - mina) + 3 * step, 0x98F198, 10, 3);
    face.add(arrow);

    if (yOpacity) {
        var y1 = new THREE.RectangleHelper(maxa, maxb, mina, minb, step, yOpacity);
        y1.rotation.z += Math.PI / 2;
        y1.rotation.y += Math.PI / 2;
        face.add(y1);
    }
   

    var yText = new THREE.THREEDTextHelper({ text: 'y' }, Tracking3DApp.Geometries);
    yText.position.set(-step + minb, maxa + 3 * step, -step);
    face.add(yText);
    
//    var loader = new THREE.JSONLoader();
//    loader.load('js/dong.js', function (geometry, mat) {
//        var mesh = new THREE.Mesh(geometry, mat[0]);
//        mesh.scale.x = 5;
//        mesh.scale.y = 5;
//        mesh.scale.z = 5;
//
//        mesh.position.set(-step + minb, maxa + 3 * step, -step);
//        face.add(mesh);
//    });

    for (var i = mina; i <= maxa; i += step) {
        var value = new THREE.THREEDTextHelper({ text: i, size: scaleSize }, Tracking3DApp.Geometries);
        value.position.set(-step / 4 + minb, i, -step / 4);
        face.add(value);
    }

    return face;
};

Axis.prototype.createZFace = function (maxa, maxb, mina, minb, step) {
    var face = new THREE.Object3D();
    
    var arrow = new THREE.ArrowHelper(new THREE.Vector3(0, 0, 1), new THREE.Vector3(0, minb, mina), (maxa - mina) + 3 * step, 0x7B68EE, 10, 3);

    face.add(arrow);
    
    if (zOpacity) {
        var z1 = new THREE.RectangleHelper(maxa, maxb, mina, minb, step, zOpacity);
        z1.rotation.x -= Math.PI / 2;
        z1.rotation.z -= Math.PI / 2;

        face.add(z1);
    }
   
    var zText = new THREE.THREEDTextHelper({ text: 'z' }, Tracking3DApp.Geometries);
    zText.position.set(-step, -step + minb, maxa + 3 * step);
        face.add(zText);
    
//    var loader = new THREE.JSONLoader();
//    loader.load('js/dong.js', function (geometry, mat) {
//        var mesh = new THREE.Mesh(geometry, mat[0]);
//        mesh.scale.x = 5;
//        mesh.scale.y = 5;
//        mesh.scale.z = 5;
//
//        mesh.position.set(-step, -step + minb, maxa + 3 * step);
//        face.add(mesh);
//    });

    for (var i = mina; i <= maxa; i += step) {
        var value = new THREE.THREEDTextHelper({ text: i, size: scaleSize }, Tracking3DApp.Geometries);
        value.position.set(-step / 4, -step / 4 + minb, i);
        face.add(value);
    }


    return face;
};